<?php
/**
 * Created by PhpStorm.
 * User: lili
 * Date: 2018/11/17
 * Time: 15:48
 */

namespace app\index\model;


use think\Model;
use traits\model\SoftDelete;

class Item extends Model
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = true;


    /*
     * 获得血糖监测的items
     * 例如，输入血糖的id=1，输入睡前，凌晨等等的id和子items信息，递归获得
     * @param int $pid 父级id
     * @return array 递归的父级以及子孙items
     * */
    public function getItems($pid=0){
        $w['pid'] = $pid;
        $items = $this->where($w)->select();
        if (!empty($items)){
            foreach ($items as $i => $v){
                $items[$i]['children'] = $this->getItems($v['itemid']);
            } 
        }
        return $items;
    }

}